/*
 *  Copyright 2010 Wesley Gooch, Ryan Nix, Cody Wenzel.
 *  Montana State University - Spring Semester 2010
 *  Computer Science 450 - Compilers
 *  Project: Micro-Pascal Compiler
 */

package msu.compiler.scanner.fsas;

import msu.compiler.scanner.Token;
import msu.compiler.scanner.Tokenizer;

/**
 *
 * @author Wesley Gooch
 */
public class DigitFSA extends FSA {
    
    public DigitFSA(Tokenizer tokenizer) {
        super(tokenizer);
        initializeStates(8);
    }

    public void execute() {
        Character currentChar;
        while(notFinished()) {
            currentChar = getCurrentChar();
            switch(getCurrentState()){
                case 0:
                    if(Tokenizer.isDigit(currentChar)){
                        setAcceptState("s1", Token.MP_INTEGER_LIT);
                        peekAhead();
                    }else{
                        fail();
                    }
                    break;
                case 1:
                    if(Tokenizer.isDigit(currentChar)){
                        setAcceptState("s1", Token.MP_INTEGER_LIT);
                        peekAhead();
                    }else if(currentChar == '.'){
                        setCurrentState("s2");
                        peekAhead();
                    }else if(Character.toUpperCase(currentChar) == 'E'){
                        setCurrentState("s4");
                        peekAhead();
                    }else{
                        fail();
                    }
                    break;
                case 2:
                    if(Tokenizer.isDigit(currentChar)){
                        setAcceptState("s3", Token.MP_FIXED_LIT);
                        peekAhead();
                    }else{
                        fail();
                    }
                    break;
                case 3:
                    if(Tokenizer.isDigit(currentChar)){
                        setAcceptState("s3", Token.MP_FIXED_LIT);
                        peekAhead();
                    }else if(Character.toUpperCase(currentChar) == 'E'){
                        setCurrentState("s4");
                        peekAhead();
                    }else{
                        fail();
                    }
                    break;
                case 4:
                    if(Tokenizer.isDigit(currentChar)){
                        setAcceptState("s6", Token.MP_FLOAT_LIT);
                        peekAhead();
                    }else if(currentChar == '+' || currentChar == '-'){
                        setCurrentState("s5");
                        peekAhead();
                    }else{
                        fail();
                    }
                    break;
                case 5:
                    if(Tokenizer.isDigit(currentChar)){
                        setAcceptState("s6", Token.MP_FLOAT_LIT);
                        peekAhead();
                    }else{
                        fail();
                    }
                    break;
                case 6:
                    if(Tokenizer.isDigit(currentChar)){
                        setAcceptState("s6", Token.MP_FLOAT_LIT);
                        peekAhead();
                    }else{
                        fail();
                    }
                    break;

                default:
                    fail();
                    break;
            }
        }
    }

}
